package com.nangle.managehost.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;


import com.nangle.managehost.R;

import com.nangle.managehost.entity.Patient;

import java.util.List;

/**
 * 作者：Administrator on 2016/10/18 16:11
 * 描述：
 */

public class PatientAdapter extends BaseAdapter {
    private LayoutInflater mInflater;
    private Context mContext;
    private List<Patient> mDatas;

    public PatientAdapter(Context context, List<Patient> mDatas) {

        mInflater = LayoutInflater.from(context);
        this.mContext = context;
        this.mDatas = mDatas;
    }


    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.patient_item, parent,
                    false);
            viewHolder = new ViewHolder();
            viewHolder.name = (TextView)convertView.findViewById(R.id.patient_name);
            viewHolder.bed = (TextView)convertView.findViewById(R.id.bed);
            viewHolder.sex = (TextView)convertView.findViewById(R.id.patient_sex);
            viewHolder.diet = (TextView)convertView.findViewById(R.id.diet);
            viewHolder.nursingGrade = (TextView)convertView.findViewById(R.id.nursing_grade);

            viewHolder.tvYe = (TextView)convertView.findViewById(R.id.tv_ye);
            viewHolder.tvWen = (TextView)convertView.findViewById(R.id.tv_wen);
            viewHolder.tvShu = (TextView)convertView.findViewById(R.id.tv_shu);
            viewHolder.tvGuan = (TextView)convertView.findViewById(R.id.tv_guan);
            viewHolder.tvJia = (TextView)convertView.findViewById(R.id.tv_jia);
            viewHolder.tvage = (TextView)convertView.findViewById(R.id.patient_age);
            viewHolder.llyTime = (LinearLayout)convertView.findViewById(R.id.lly_time);
            viewHolder.rlyBaseMsg = (RelativeLayout)convertView.findViewById(R.id.lly_bese_msg);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        Patient patient = mDatas.get(position);
        viewHolder.name.setText(patient.getName());
        if(patient.getSex()==0){
            viewHolder.sex.setText("女");
        }else{
            viewHolder.sex.setText("男");
        }
        if(patient.getName().equals("")){
            viewHolder.tvYe.setVisibility(View.INVISIBLE);
            viewHolder.tvWen.setVisibility(View.INVISIBLE);
            viewHolder.tvShu.setVisibility(View.INVISIBLE);
            viewHolder.tvGuan.setVisibility(View.INVISIBLE);
            viewHolder.tvJia.setVisibility(View.INVISIBLE);
            viewHolder.diet.setVisibility(View.INVISIBLE);
            viewHolder.nursingGrade.setVisibility(View.INVISIBLE);
            viewHolder.sex.setVisibility(View.INVISIBLE);
            viewHolder.tvage.setVisibility(View.INVISIBLE);
            viewHolder.llyTime.setVisibility(View.INVISIBLE);
            viewHolder.rlyBaseMsg.setVisibility(View.INVISIBLE);
        }else{
            viewHolder.tvYe.setVisibility(View.VISIBLE);
            viewHolder.tvWen.setVisibility(View.VISIBLE);
            viewHolder.tvShu.setVisibility(View.VISIBLE);
            viewHolder.tvGuan.setVisibility(View.VISIBLE);
            viewHolder.tvJia.setVisibility(View.VISIBLE);
            viewHolder.diet.setVisibility(View.VISIBLE);
            viewHolder.nursingGrade.setVisibility(View.VISIBLE);
            viewHolder.sex.setVisibility(View.VISIBLE);
            viewHolder.tvage.setVisibility(View.VISIBLE);
            viewHolder.llyTime.setVisibility(View.VISIBLE);
            viewHolder.rlyBaseMsg.setVisibility(View.VISIBLE);
        }
        viewHolder.bed.setText(""+patient.getBed());

        if(patient.getNursingGrade()==1){
            viewHolder.nursingGrade.setText("Ⅰ级护理");
            viewHolder.nursingGrade.setTextColor(mContext.getResources().getColor(R.color.colorwrite));
            viewHolder.nursingGrade.setBackgroundResource(R.drawable.shape_corner_red);
            viewHolder.nursingGrade.setVisibility(View.VISIBLE);
        }else if(patient.getNursingGrade()==2){
            viewHolder.nursingGrade.setText("Ⅱ级护理");
            viewHolder.nursingGrade.setTextColor(mContext.getResources().getColor(R.color.black));
            viewHolder.nursingGrade.setBackgroundResource(R.drawable.shape_corner_yellow);
            viewHolder.nursingGrade.setVisibility(View.VISIBLE);
        }else if(patient.getNursingGrade() == 3){
            viewHolder.nursingGrade.setText("Ⅲ级护理");
            viewHolder.nursingGrade.setTextColor(mContext.getResources().getColor(R.color.colorwrite));
            viewHolder.nursingGrade.setBackgroundResource(R.drawable.shape_corner_blue);
            viewHolder.nursingGrade.setVisibility(View.VISIBLE);
        }else if(patient.getNursingGrade()==4){
            viewHolder.nursingGrade.setText("特级护理");
            viewHolder.nursingGrade.setTextColor(mContext.getResources().getColor(R.color.colorwrite));
            viewHolder.nursingGrade.setBackgroundResource(R.drawable.shape_corner_dark_red);
            viewHolder.nursingGrade.setVisibility(View.VISIBLE);
        }else{
            viewHolder.nursingGrade.setVisibility(View.GONE);
        }

        if(patient.isYe()>0){
            viewHolder.tvYe.setBackgroundResource(R.drawable.orange_bg);
            viewHolder.tvYe.setTextColor(mContext.getResources().getColor(R.color.orange));
        }else{
            viewHolder.tvYe.setBackgroundResource(R.drawable.light_grey);
            viewHolder.tvYe.setTextColor(mContext.getResources().getColor(R.color.light_gray));
        }
        if(patient.isWen() ==1){
            viewHolder.tvWen.setBackgroundResource(R.drawable.orange_bg);
            viewHolder.tvWen.setTextColor(mContext.getResources().getColor(R.color.orange));
        }else{
            viewHolder.tvWen.setBackgroundResource(R.drawable.light_grey);
            viewHolder.tvWen.setTextColor(mContext.getResources().getColor(R.color.light_gray));
        }
        if(patient.isShu()>0){
            viewHolder.tvShu.setBackgroundResource(R.drawable.orange_bg);
            viewHolder.tvShu.setTextColor(mContext.getResources().getColor(R.color.orange));
        }else{
            viewHolder.tvShu.setBackgroundResource(R.drawable.light_grey);
            viewHolder.tvShu.setTextColor(mContext.getResources().getColor(R.color.light_gray));
        }
        if(patient.isGuan()>0){
            viewHolder.tvGuan.setBackgroundResource(R.drawable.orange_bg);
            viewHolder.tvGuan.setTextColor(mContext.getResources().getColor(R.color.orange));
        }else{
            viewHolder.tvGuan.setBackgroundResource(R.drawable.light_grey);
            viewHolder.tvGuan.setTextColor(mContext.getResources().getColor(R.color.light_gray));
        }
        if(patient.isJia()>0){
            viewHolder.tvJia.setBackgroundResource(R.drawable.orange_bg);
            viewHolder.tvJia.setTextColor(mContext.getResources().getColor(R.color.orange));
        }else{
            viewHolder.tvJia.setBackgroundResource(R.drawable.light_grey);
            viewHolder.tvJia.setTextColor(mContext.getResources().getColor(R.color.light_gray));
        }
        return convertView;
    }

    private final class ViewHolder {
        private TextView name;
        private TextView sex;
        private TextView nursingGrade;
        private TextView bed;
        private TextView tvYe;
        private TextView tvWen;
        private TextView diet;
        private TextView tvShu;
        private TextView tvGuan;
        private TextView tvJia;
        private TextView tvage;
        private LinearLayout llyTime;
        private RelativeLayout rlyBaseMsg;
    }

}